/*
 * @Description: 自动处置
 * @Author: Zzt
 * @Date: 2022-11-11 14:52:39
 * @LastEditTime: 2022-12-26 10:38:50
 */
import VisualizationMain from '@/components/DataVisualization/VisualizationMain';
import classNames from 'classnames/bind';
import { useEffect, useState } from 'react';
import { useFamilyStatisticsContext } from '../contexts/FamilyStatisticsContext';
import styles from '../styles/familyStatistics.module.scss';
const cx = classNames.bind(styles);

const table: any[] | (() => any[]) = [];

const segmentedList = [
  { label: '案卷总量', value: 'folderCounts' },
  { label: '文件总量', value: 'fileCounts' },
  { label: '电子文件总量', value: 'eFileCounts' }
];
const Time = (props: any) => {
  const { ATList } = props;

  const { timeList, periodList, setTime } = useFamilyStatisticsContext();
  const [changedValue, setChangeValue] = useState({});

  // 选中的按照类型
  // const [options, setOptions] = useState();
  const [visibleData, setVisibleData] = useState([]);
  const [condition, setCondition] = useState(<></>);
  const [tableList, setTableList] = useState(table);
  const [segmentValue, setSegmentValue] = useState('folderCounts');

  const [xData, setXData] = useState();
  const [yData, setYData] = useState([]);

  useEffect(() => {
    setTime(changedValue);
  }, [changedValue]);

  useEffect(() => {
    setVisibleData(timeList);
    setYData(timeList?.map((item: any) => item?.name));
    setXData(timeList?.map((item: any) => item[segmentValue]));
    setCondition(<></>);
  }, [timeList, segmentValue]);
  /* 改变触发 */
  const onChangeYear = (value: any) => {
    setChangeValue({ ...value.chioce });
    setSegmentValue(value.segmentValue);
  };
  return (
    <>
      <h2 className={cx('title')}>按时间统计</h2>
      <VisualizationMain
        type={'时间'}
        condition={condition}
        segmented={segmentedList}
        tableList={tableList}
        choiceList={[
          { title: '档案类型', name: 'archiveTypeIds', checkList: ATList },
          {
            title: '密级',
            name: 'secrets',
            checkList: [
              { value: 1, label: '绝密' },
              { value: 2, label: '机密' },
              { value: 3, label: '秘密' },
              { value: 4, label: '公开' }
            ]
          },
          {
            title: '保管期限',
            name: 'retentionPeriods',
            checkList: periodList
          }
        ]}
        data={{ visibleData, xData, yData }}
        onChange={onChangeYear}
      />
    </>
  );
};
export default Time;
